import {ApiResult} from '@/phr/common/ApiResult';
import HttpClient from '@/phr/common/HttpClient';
import {Appointment} from '@/phr/service/hospital/Appointment';

/**
 * 自助挂号服务API接口
 */
class AppointmentService {

  private DO_APPOINTMENT_URL = 'appointment/api/do';
  private QUERY_APPOINTMENT_URL = 'appointment/api/get';


  /**
   * 自助挂号接口
   * 注意，该接口只有当用户已经登录才有效，测试阶段可以在phrConf.js设置一个已经登录的TOKEN
   * @param {number} id  医院ID
   * @param {string} department 部门名称
   * @param {string} doctor 医生名称
   * @param {string} startDate 开始时间，格式要符合 yyyy-mm-dd ,否则会解析失败
   * @returns {Promise<ApiResult<any>>} errorCode == 200表示成功
   */
  public async doAppointment(id: number, department: string, doctor: string, startDate: string): Promise<ApiResult<any>> {
    let params = {
      hospitalId: id,
      department: department,
      doctor: doctor,
      startDate: startDate
    };
    return HttpClient.get(this.DO_APPOINTMENT_URL, params);
  }

  /**
   * 查询挂号历史接口
   * 返回当前登录用户的所有挂号历史(数据不会很多，不分页)
   * @returns {Promise<ApiResult<Appointment[]>>}
   */
  public async queryAppointmentHistory(): Promise<ApiResult<Appointment[]>> {
    return HttpClient.get(this.QUERY_APPOINTMENT_URL);
  }
}

export default new AppointmentService()